{include file='public/header'}


<div class="layui-body">
    <!--tab标签-->
    <div class="layui-tab layui-tab-brief">
        <ul class="layui-tab-title">
            <li class="layui-this">修改密码</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <div class="layui-form-item">
                    <label class="layui-form-label">旧密码</label>
                    <div class="layui-input-block">
                        <input type="password" name="old_password" value="" required lay-verify="required"
                               placeholder="请输入原密码" class="layui-input" onblur="chk()" id="password"/>
                        <span class="layui-span"></span>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">新密码</label>
                    <div class="layui-input-block">
                        <input type="password" name="password" value="" placeholder="请输入新密码" class="layui-input"
                               onblur="chk()"
                               id="password1"

                        />
                        <span class="layui-span1"></span>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">重复密码</label>
                    <div class="layui-input-block">
                        <input type="password" name="confirm_password" value="" placeholder="请再次输入新密码"
                               id="password2"
                               onblur="chk();"
                               class="layui-input">
                        <span class="layui-span2"></span>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" onclick="chk1()" lay-filter="*">更新</button>
                        <button type="reset" class="layui-btn layui-btn-primary" onclick="chk2()">重置</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</div>
<script>
    var str ="";
    var bool=false;
    var a = 0;
    var b =0;
    var c =0;



    var chk =function () {
        var pas = $('#password').val();
        $.post('./revise',{p:pas},function (msg) {
            if(msg.error == 0){
                str =msg.msg;
                $('.layui-span').html(str);
                $('.layui-span').css('color','green');
                a = 1;
            }else if(msg.error == 1){
                str =msg.msg;
                $('.layui-span').html(str);
                $('.layui-span').css('color','red')
                a=2;
            }
        });
        if(pas == "" || pas ==undefined){
            $('.layui-span').html('密码错误');
            $('.layui-span').css('color','red');
            $('#password').val('');
            a = 0;
            return ;
        }


        var pas2 = $('#password1').val();
        if(pas == pas2){
            $('.layui-span1').html('不能和原密码一致');
            $('.layui-span1').css('color','red');
            $('#password1').val('').focus();
            b=0;
            return;
        }else if(pas2 =="" || pas2==undefined){
            $('.layui-span1').html('新密码不能为空');
            $('.layui-span1').css('color','red');
            $('#password1').val('');
            b=2;
            return;
        }else{
            $('.layui-span1').html('密码可用');
            $('.layui-span1').css('color','green');
            b=1;
        }
        var pas3 = $('#password2').val();
        if(pas3 == "" || pas3==undefined){
            $('.layui-span2').html('重复密码不能为空');
            $('.layui-span2').css('color','red');
            $('#password2').val('');
            c=2;
            return;
        }else if(pas3 != pas2){
            $('.layui-span2').html('重复密码不一致');
            $('.layui-span2').css('color','red');
            $('#password2').val('');
            c=0;
            return;
        }else if(pas3 == pas2){
            $('.layui-span2').html('密码可用');
            $('.layui-span2').css('color','green');
            c=1;
        }


    }
    var chk1 =function () {
        if(a == 0){
            alert('请输入密码');
            $('#password').focus();
            return;
        }else if(a == 2){
            alert('密码错误');
            $('#password').val("").focus();
            return;
        }
        if(b == 0){
            alert('不能和愿密码一致');
            $('#password1').focus();
            return;
        }else if(b == 2){
            alert('新密码不能为空');
            return;
        }
        if( c == 0){
            alert('重复密码不一致');
            $('#password2').focus();
            return;
        }else if(c == 2){
            alert('重复密码不能为空');
            $('#password2').focus();
            return;
        }

        if(a == 1 && b ==1 && c ==1){
            var pas2 =$('#password1').val();

            $.post('./detail',{p:pas2},function (msg) {
                if(msg.error == 0){
                    alert(msg.msg);
                    window.location.href=msg.url;
                }

            })
        }
    }
    var chk2 = function () {
        window.location.reload();
    }
</script>



<!--页面JS脚本-->

</body>
</html>